perm filename LIMT.SAI[PIC,HE] blob sn#430351 filedate 1979-04-04 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	*********************************
C00005 00003	simple internal procedure slimit(integer hbuf,sbuf
C00008 ENDMK
C⊗;
comment *********************************
 Program: Limit - for use in all those histogram programs
	so that it can be more easily changed etc.

	K. Price 9-May-75
 ***************************************** ;

entry limit,SLIMIT;
begin "limt"
REQUIRE "BAYSAI.SAI" SOURCE!FILE;
SOURCE!L(UTILS.DCL);
SOURCE!L(PICBUF.DCL);
simple internal procedure limit(integer buffr; safe integer array pixels;
	reference integer min,max,sum;
	integer maskin,mask);
begin "limit"
integer byt,ilim,jlim,i,j,iptr,mptr,iincr,jincr;

min←-1;
max←sum←0;
byt←2↑bytsz(buffr)-1;
arrclr(pixels);					! initialize array to 0;
if maskin then begin
    IINCR←ISUBST(mask)-ISUBST(buffr);
    JINCR←JSUBST(mask)-JSUBST(buffr)+1;
    ilim←rows(mask);
    jlim←colms(mask);
    end
   else begin
    ilim←rows(buffr);
    jlim←colms(buffr);
    end;

if maskin=0 then					! no mask;
    FOR I←1 THRU Ilim DO
	BEGIN
	iptr←INPTR(I,1,buffr);
	FOR J←1 THRU Jlim DO
	    BEGIN
	    add1(PIXELS[ILDB(IPTR)]);
	    END;
	END
  else							! has a mask;
    FOR I←1 THRU Ilim DO
	BEGIN
	iptr←INPTR(I+iincr,jincr,buffr);
	mptr←inptr(i,1,mask);
	FOR J←1 THRU Jlim DO
	    if ildb(mptr) then
		BEGIN
		add1(PIXELS[ILDB(IPTR)]);
		END
	      else ibp(iptr);
	END;
for i←0 thru byt do
    begin
    sum←sum+pixels[i]*i;
    if pixels[i] then if min≥0 then max←i else min←max←i;
    end;
end "limit";
simple internal procedure slimit(integer hbuf,sbuf;
	safe integer array pixels;
	reference integer min,max,sum;
	integer maskin,mask);

begin "Slimit"
integer ilim,jlim,i,j,hptr,sptr,picuse;

define F(Sat) = "Sat";

arrclr(pixels);					! initialize array to 0;
if not maskin then begin
    ilim←rows(hbuf);
    jlim←colms(hbuf);
    FOR I←1 THRU Ilim DO
	BEGIN
	hptr←INPTR(I,1,hbuf);
	sptr←INPTR(i,1,sbuf);
	FOR J←1 THRU Jlim DO
	    BEGIN
	    PICUSE←ildb(hptr);
	    PIXELS[picuse]←PIXELS[picuse]+F(ildb(sptr));
	    END;
	END;
    end
   else begin "mask exists"
    integer mptr,iincr,jincr;
    IINCR←ISUBST(mask)-ISUBST(hbuf);
    JINCR←JSUBST(mask)-JSUBST(hbuf)+1;
    ilim←rows(mask);
    jlim←colms(mask);
    FOR I←1 THRU Ilim DO
	BEGIN
	hptr←INPTR(I+iincr,jincr,hbuf);
	sptr←INPTR(I,1,sbuf);
	mptr←inptr(i,1,mask);
	FOR J←1 THRU Jlim DO
	    if ildb(mptr) then
		BEGIN
		PICUSE←ILDB(hptr);
		PIXELS[picuse]←PIXELS[picuse]+F(ildb(sptr));
		END
	      else begin ibp(hptr); ibp(sptr); end;
	END;
    end "mask exists" ;


begin "calculate min max sum"
	integer byt;
	byt←2↑bytsz(hbuf)-1;
	min←-1;
	max←sum←0;
	for i←0 thru byt do
	    begin
	    sum←sum+pixels[i]*i;
	    if pixels[i] then if min≥0 then max←i else min←max←i;
	    end;
end "calculate min max sum";


end "Slimit";
end "limt";